home *** CD-ROM | disk | FTP | other *** search
- Path: hilbert.dnai.com!usenet
- From: Victor Bazarov <vbazarov@imsisoft.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Fastest way to index thru an array????
- Date: Fri, 12 Jan 1996 11:05:26 -0800
- Organization: IMSI
- Message-ID: <30F6B0F6.75E3@imsisoft.com>
- References: <4d1g3k$o09@solaris.cc.vt.edu> <4d34p7$kj9@tahko.lpr.carel.fi>
- NNTP-Posting-Host: vbazarov.imsisoft.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b4a (Win16; I)
-
- Ari Lukumies wrote:
- > Ashutosh Gokhale <ashutosh> wrote:
- >
- > >Suppose I have an array A[][][] which I declare as
- > > double ***A and then assign memory to it using new operator.
- > >Now consider that A has dimensions A[50][60][70]. Then I can index thru ALL
- > >entries of A using[...]
- > Try this:
- >
- > double *p = A;
- >
- > for (i = 0; i < 50*60*70; i++)
- > *p++ = <some expression>;
- >
- > BTW, array indexes in C/C++ begin at 0, _not_ at 1.
- >
-
- What if he's got to use index to every dimension in <some expression>?
-
- Try this:
-
- double* ppp = A;
- for (i = 0; i < 50; i++)
- {
- double* pp = ppp;
- for (j = 0; j < 60; j++)
- {
- double* p = pp;
- for (k = 0; k < 70; k++)
- *p++ = <some expression>;
- pp = p;
- }
- ppp = pp;
- }
-
- it's definitely slower that one cycle, but will allow to use
- i,j,k in <some expression>.
-
-
- > Later,
- > AriL
- >
- > All my opinions are mine and mine alone.
-
- Oh yeah!
-
- Victor.
-
- --
- Signature.
-